﻿using BLL;
using System;
using System.Data;
using System.Web.UI.WebControls;

namespace Thksoft.BusinessExpansion.Process
{
    public partial class Test : System.Web.UI.Page
    {
        public DataTable dt_allRecord;

        public DataView dv_allRecord;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                GridView1.Attributes.Add("style", "table-layout:fixed");
                ViewState["SortOrder"] = "N_QUEUE_ID";
                ViewState["OrderDire"] = " asc ";
                bind();

                dt_allRecord = new QS_PROJECTBLL().SelectBy("");
                dv_allRecord = new DataView(dt_allRecord);

                //dg1.DataSource = dt_allRecord;
                //dg1.DataBind();
            }
        }

        //dt_allRecord = SqlHelper.ExecuteDataset(siteInfo.Instant.connectionString
        //, CommandType.StoredProcedure, "sms_getlocationClasslist").Tables[0];
        //dv_allRecord = new DataView(dt_allRecord);

        //this.dg1.DataSource = dt_allRecord;
        //this.dg1.DataBind();

        public string strclass(int classid)
        {
            if (classid == 0)
            {
                dv_allRecord.RowFilter = "";
            }
            else
            {
                dv_allRecord.RowFilter = "id=" + classid.ToString();
            }

            string classname = "";

            System.Data.DataView dv_temp = new DataView(dt_allRecord);
            dv_temp.RowFilter = "parentId=" + classid;

            int childCount = dv_temp.Count;

            classname += "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
            classname += "<tr>";

            for (int j = 0; j < dv_allRecord.Count; j++)
            {
                DataRowView dr = dv_allRecord[j];

                int depth;
                depth = Convert.ToInt32(dr["depth"]);

                if (depth > 0)
                {
                    for (int i = 1; i <= depth; i++)
                    {
                        #region .....

                        classname += "<td style =\"width :33px; height :21px; background-color :#F6F6F6;\"></td>";
                        if (i == depth)
                        {
                            if (childCount > 0)
                            {
                                classname += "<td style =\"width :21px; height :21px; background-image :url(../images/tree_close.gif);\" onclick=\"hideOrShowTr(this,'" + dr["jsparameter"].ToString() + "'," + dr["rownumber"].ToString() + ")\" id=\"hideshowbtn" + classid + "\"></td>";
                            }
                            else
                            {
                                classname += "<td style =\"width :21px; height :21px; background-image :url(../images/treeleaf.gif);\"></td>";
                            }
                        }

                        #endregion .....
                    }
                }
                else
                {
                    if (childCount > 0)
                    {
                        classname += "<td style =\"width :21px; height :21px; background-image :url(../images/tree_close.gif);\" onclick=\"hideOrShowTr(this,'" + dr["jsparameter"].ToString() + "'," + dr["rownumber"].ToString() + ")\" id=\"hideshowbtn" + classid + "\"></td>";
                    }
                }

                classname += "<td align =\"left\">";
                if (Convert.ToInt32(dr["parentId"]) == 0)
                {
                    classname += "<b>";
                }
                classname += dr["className"].ToString();
                if (childCount > 0)
                    classname += "(子类数:" + childCount + ")";
                classname += "</td>";
            }

            classname += "</tr>";
            classname += "</table>";
            return classname;
        }

        public void bind()
        {
            string strfaca = @"SELECT lcq.N_QUEUE_ID,
       lcp.C_PROCESS_NAME,
       lcq.N_QUEUE_NUMBER,
       lcn.c_node_name
  FROM Lc_Queue lcq, Lc_Process lcp, Lc_Node lcn
 WHERE lcq.N_PROCESS_ID = lcp.N_PROCESS_ID
   AND lcq.N_NODE_ID = lcn.N_NODE_ID ";//这里根据你自己的情况修改就行了

            DataTable dtItem = new BaseBLL().Query(strfaca);
            DataView view = dtItem.DefaultView;
            string sort = (string)ViewState["SortOrder"] + " " + (string)ViewState["OrderDire"];
            view.Sort = sort;//设置排序
            //  view.Sort=
            GridView1.DataSource = view;
            GridView1.DataBind();
        }

        protected void PageIng_DataBinding(object sender, EventArgs e)
        {
            //  BindData(false);
        }

        protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
        {
            string sPage = e.SortExpression;

            if (ViewState["SortOrder"].ToString() == sPage)
            {
                if (ViewState["OrderDire"].ToString() == "Desc")
                    ViewState["OrderDire"] = "ASC";
                else
                    ViewState["OrderDire"] = "Desc";
            }
            else
            {
                ViewState["SortOrder"] = e.SortExpression;
                ViewState["OrderDire"] = "ASC";
            }
            bind();
        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            //for (int i = 0; i < e.Row.Cells.Count; i++)
            //{//在数据绑定时，设置各列在宽度较小时，数据自动换行
            //    e.Row.Cells[i].Style.Add("word-break", "break-all");

            //}

            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("onmouseover", "cu=style.backgroundColor;style.backgroundColor='#d5e7ff'");
                e.Row.Attributes.Add("onmouseout", "style.backgroundColor=cu");
            }
        }

        protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Header)
            {
                if (true)//如果允许改变列宽
                {
                    for (int i = 0; i < e.Row.Cells.Count; i++)
                    {
                        //e.Row.Cells[i].Attributes.Add("onmousemove", "TableOnMouseMove(this)");
                        //e.Row.Cells[i].Attributes.Add("onmousedown", "TableOnMouseDown(this)");
                        //e.Row.Cells[i].Attributes.Add("onmouseup", "TableOnMouseUp(this)");

                        e.Row.Cells[i].Attributes.Add("onmousemove", "SyDG_moveOnTd(this)");
                        e.Row.Cells[i].Attributes.Add("onmousedown", "SyDG_downOnTd(this)");
                        e.Row.Cells[i].Attributes.Add("onmouseup", "this.mouseDown=false");
                        e.Row.Cells[i].Attributes.Add("onmouseout", "this.mouseDown=false");
                    }
                }
            }
        }

        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView1.PageIndex = e.NewPageIndex;
            bind();
        }

        protected void GridView_RowCreated(object sender, GridViewRowEventArgs e)
        {
        }
    }
}